package handles

import (
	"film-hub/models"
	"github.com/gin-gonic/gin"
)

func Add(c *gin.Context) {

	title := c.PostForm("title")
	comment := c.PostForm("comment")

	data := models.Video{

		Title:   title,
		Comment: comment,
	}

	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}

func List(c *gin.Context) {

	var video []models.Video

	models.DB.Find(&video)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "成功",
		"data": video,
	})
}
